import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    _tabController = TabController(
      length: 5,
      vsync: this,
    );
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: InkWell(
          onTap: () {},
          child: Container(
            margin: const EdgeInsets.all(8.0),
            child: CircleAvatar(
              backgroundImage: NetworkImage(
                  'https://i.loli.net/2019/02/16/5c67ca84d2306.jpeg'),
            ),
          ),
        ),
        title: TabBar(
          onTap: (index) {
            print(index);
          },
          tabs: <Widget>[
            Text('主页'),
            Text('项目'),
            Text('热门'),
            Text('动态'),
            Text('体系'),
          ],
          controller: _tabController,
          labelPadding: EdgeInsets.all(12.0),
          indicatorSize: TabBarIndicatorSize.label,
        ),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.search),
            onPressed: () {},
          )
        ],
      ),
      body: TabBarView(
        children: <Widget>[
          Center(),
          Text('data'),
          Text('data'),
          Text('data'),
          Text('data'),
        ],
        controller: _tabController,
      ),
    );
  }
}
